package _15_generics._15_9;

import java.awt.*;

/**
 * 泛型的基础边界
 */
interface HasColor {
    Color getColor();
}

class Colored<T extends HasColor> {
    T item;
    Colored(T item) {
        this.item = item;
    }
    Color color() {
        return item.getColor();
    }
}

class Dimension {
    public int x;
}

/**
 * 边界有多个时，class 需要放在第一个
 * @param <T>
 */
class ColoredDimension<T extends Dimension & HasColor> {
    T item;
    public ColoredDimension(T item){
        this.item = item;
    }

    T getItem() {
        return item;
    }

    Color color() {
        return item.getColor();
    }

    int getX(){
        return item.x;
    }
}

interface Weight {
    int weight();
}

class Solid<T extends Dimension & HasColor & Weight> {
    T item;
    public Solid(T item) {
        this.item = item;
    }

    T getItem() {
        return item;
    }

    Color color() {
        return item.getColor();
    }

    int getX(){
        return item.x;
    }

    int weight(){
        return item.weight();
    }
}

class Bounded extends Dimension implements HasColor,Weight {

    @Override
    public Color getColor() {
        return null;
    }

    @Override
    public int weight() {
        return 0;
    }
}

public class _01_BasicBounds {
    public static void main(String[] args) {
        Solid<Bounded> solid = new Solid<>(new Bounded());
        solid.color();
        solid.getX();
        solid.weight();
    }
}
